<template>
  <div class="MyCheckbox">
    <div v-for="(checkData, index) in CheckboxData" :key="index" >
      <div class="checkbox_border r_flex_wrap">
        <div class="checkbox_list r_text_none" @click="allcityChange(checkData)">
          <div class="checkbox_icon r_flex_center" :class="checkData.active?'active_icon':''">
            <i class="el-icon-check" />
          </div>
          <span>{{checkData.name}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { cityList, cityTree } from '@/api/business/city'

export default {
  name: 'MyCheckbox',
  props: {
    // 多选框 - 单选/多选
    multiple: {
      type: Boolean,
      default: true
    },
    // 多选框 - 多选数据
    CheckboxData: {
      type: Array,
      default: ()=>[]
    },
    // 多选框 - 多选数据
    activeCheck: {
      type: Array,
      default: ()=>[]
    },
    // 全选
    allchecked: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      cityData: [{
        value: 'zhinan',
        label: '指南',
        children: [{
          value: 'shejiyuanze',
          label: '设计原则',
        }],
      }],
      cityKey: '',
      cityModel: '',
    }
  },
  created() {

  },
  mounted() {
  },
  methods: {
    // 初始选中
    chushihua() {
      this.activeCheck.map(value=>{
        this.CheckboxData.filter(data=>{ if(data.value == value){ data.active = true } })
      })
    },
    /** 多选 */
    allcityChange(data) {
      data.active = !data.active
      this.$emit('checkboxChange', this.CheckboxData)
    }
  },
  watch: {
    activeCheck(data) {
      this.activeCheck = data
      this.chushihua()
    }
  }
}
</script>

<style lang="scss" scoped>
.MyCheckbox{
  display: flex;
  flex-wrap: wrap;
}
// 全局-多选样式-自定义
.checkbox_border{
  .checkbox_list{
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    margin-right: 30px;
    .checkbox_icon{
      margin: 4px 4px 4px 0;
      display: inline-block;
      position: relative;
      border: 1px solid #DCDFE6;
      border-radius: 2px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      width: 14px;
      height: 14px;
      background-color: #FFFFFF;
      .el-icon-check{
        display: block;
        font-size: 12px;
        color: #fff;
      }
    }
    .active_icon{
      background: #918ef9;
      border: 1px solid #918ef9;
      overflow: hidden;
    }
  }
}
</style>
